﻿﻿<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>预排产工序点检</title>
  <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
  <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
  <style>
    .inline-block {
      display: inline-block;
    }

    .divLabel {
      margin-bottom: 5px;
    }

    /* 重写下拉框样式 */
    .select {
      width: 200px;
    }

    .combobox-item {
      height: 32px;
    }

    /* 重写日期框样式 */
    .datebox {
      height: 24px !important;
      line-height: 24px !important;
    }

    /* 重写文本框样式 */
    #queryZone .textbox-text,
    #editZone .textbox-text {
      line-height: 22px !important;
      height: 22px !important;
    }

    .l-btn-custom {
      height: 24px !important;
    }
  </style>
</head>

<body>
  <div class="panelSection" id="queryZone">
    <div class="easyui-panel " title="查询区域" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div class="inline-block">
        <div class="divLabel">分厂:</div>
        <select id='ddlFactory' data-options='editable:true' class='easyui-combobox select'
          style="width:160px;"></select>
      </div>

      <div class="inline-block">
        <div class="divLabel">订单号:</div>
        <input id="txtMfgordername" name="txtMfgordername" class="easyui-textbox" style="width:140px;" />
      </div>

      <div class="inline-block">
        <div class="divLabel">零件号:</div>
        <input id="txtProductname" name="txtProductname" class="easyui-textbox" style="width:140px;" />
      </div>

      <div class="inline-block">
        <div class="divLabel">批次号:</div>
        <input id="txtContainername" name="txtContainername" class="easyui-textbox" style="width:200px;" />
      </div>

      <div class="inline-block">
        <div class="divLabel">工序:</div>
        <input id="txtWorkflowstepname" name="txtWorkflowstepname" class="easyui-textbox" style="width:140px;" />
      </div>

      <div class="inline-block">
        <div class="divLabel">点检状态:</div>
        <select id='ddlCheck' value="请选择" data-options='editable:false' class='easyui-combobox select'
          style="width:100px;">
        </select>
      </div>
      <div class="inline-block">
        <div class="divLabel">计划开始/结束时间:</div>
        <input id="planStartDate"  class="easyui-datebox select"  style="width:130px;"/>-
        <input id="planEndDate"  class="easyui-datebox select"  style="width:130px;"/>
      </div>

      <button id="btnSearch" class="easyui-linkbutton" data-options="">查 询</button>
      <button id="btnReset" class="easyui-linkbutton" data-options="">重 置</button>
      <button id="btnExport" class="easyui-linkbutton" data-options="">导 出</button>

      <div style="margin-top: 10px;">
        <div class="inline-block">
          <div class="divLabel">是否齐套:</div>
          <select id='ddlAllSet' name="ddlAllSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">物料齐套:</div>
          <select id='ddlMaterialSet' name="ddlMaterialSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">工装工具齐套:</div>
          <select id='ddlToolSet' name="ddlToolSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">辅材齐套:</div>
          <select id='ddlAuxSet' name="ddlAuxSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">工艺齐套:</div>
          <select id='ddlWorkflowSet' name="ddlWorkflowSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">数控程序齐套:</div>
          <select id='ddlNcProgramSet' name="ddlNcProgramSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">特殊过程齐套:</div>
          <select id='ddlCheckPointSet' name="ddlCheckPointSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">设备齐套:</div>
          <select id='ddlResourceSet' name="ddlResourceSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">实物齐套:</div>
          <select id='ddlShipStepSet' name="ddlShipStepSet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>

        <div class="inline-block">
          <div class="divLabel">质量齐套:</div>
          <select id='ddlQualitySet' name="ddlQualitySet" value="请选择" data-options='editable:false'
            class='easyui-combobox select' style="width:100px;">
          </select>
        </div>
      </div>
    </div>
  </div>

  <div class="panelSection" id="dataGridZone">
    <div class="easyui-panel " title="查询结果" style="padding: 3px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div style="background: #fff; margin: 3px 0px 3px 3px">
        <table id="tbGrid" class="easyui-datagrid" style="height: 350px;" data-options="rownumbers:true">
        </table>
        <div id="pp" style="float: right" class="easyui-pagination" data-options="
                      layout:['list','first','prev','next','last','manual','info'],
                        total: 0,
                        showPageList: true,
                        showPageInfo: false,
                        showRefresh: false,
                        pageList:[10,20,50,100,200],
                        afterPageText:'共&nbsp{pages}&nbsp页'">
        </div>
      </div>
    </div>
  </div>

  <div class="panelSection" id="editZone">
    <div class="easyui-panel " title="明细信息" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div id="tabs" class="easyui-tabs" style="width:100%;height:200px">
        <div title="物料明细" style="padding:10px">
          <table id="tbMaterials" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div>
        <!-- <div title="实物明细" style="padding:10px">
          <table id="tbShip" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div> -->
        <div title="工装工具" style="padding:10px">
          <table id="tbTools" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div>
        <div title="辅材" style="padding:10px">
          <table id="tbAuxs" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div>
        <div title="特殊过程" style="padding:10px">
          <table id="tbCheckPoint" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div>
        <div title="数控程序" style="padding:10px">
          <table id="tbNcProgram" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div>
        <div title="设备" style="padding:10px">
          <table id="tbResource" class="easyui-datagrid" data-options="rownumbers:true"></table>
        </div>
      </div>
    </div>
  </div>

  <div class="panelSection" id="editZone">
    <div class="easyui-panel " title="操作区域" style="padding:3px 3px 5px;"
      data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
      <div class="inline-block">
        <div class="divLabel">物料齐套:</div>
        <select id='ddlMaterialSet2' name="ddlMaterialSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">工装工具齐套:</div>
        <select id='ddlToolSet2' name="ddlToolSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">辅材齐套:</div>
        <select id='ddlAuxSet2' name="ddlAuxSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">数控程序齐套:</div>
        <select id='ddlNcProgramSet2' name="ddlNcProgramSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">特殊过程齐套:</div>
        <select id='ddlCheckPointSet2' name="ddlCheckPointSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">实物齐套:</div>
        <select id='ddlShipStepSet2' name="ddlShipStepSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">预齐套时间:</div>
        <input id="txtEstAllSetDate" name="txtEstAllSetDate" type="text" class="easyui-datetimebox"
          style="height: 20px;width: 170px" data-options='editable:false' />
      </div>

      <div style="margin-left: 50px;" class="inline-block">
        <div class="divLabel">工艺齐套:</div>
        <select id='ddlWorkflowSet2' name="ddlWorkflowSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">设备齐套:</div>
        <select id='ddlResourceSet2' name="ddlResourceSet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>

      <div class="inline-block">
        <div class="divLabel">质量齐套:</div>
        <select id='ddlQualitySet2' name="ddlQualitySet" value="请选择" data-options='editable:false'
          class='easyui-combobox select' style="width:100px;">
        </select>
      </div>
    </div>
  </div>

  <div style="margin:5px;">
    <button id="btnCompute" class="easyui-linkbutton" data-options="">点检确认</button>
    <button id="btnKeyCompute" class="easyui-linkbutton" data-options="">一键点检</button>
    <button id="btnReCompute" class="easyui-linkbutton" data-options="">再次点检</button>
    <button id="btnAllSet" class="easyui-linkbutton" data-options="">一键齐套</button>
    <button id="btnUpdate" class="easyui-linkbutton" data-options="">修改齐套</button>
    <button id="btnUpdateQuality" class="easyui-linkbutton" data-options="">修改工艺、设备、质量齐套</button>
  </div>
</body>

</html>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/array.pollyfill.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ProductLinkageWorkflow2.js" type="text/javascript"></script>
<script type="text/javascript">
  /**
   * 创建人：zhunan
   * 日期：2024.12.17
   * 预排产工序点检
  */
  var page = {
    pagetotal: 0,
    pageNumber: 1,
    pageSize: 10,
    DBDataSet: null,
    row: {},
    mainUrl: getRootPath() + "/Ashx/ApsHandler/ApsPlanInfoPreSpotCheckHandler.ashx", //本页面后台路径
    //初始化页面
    init: function () {
      page.bind();
      page.initData(); //初始化页面数据
    },
    // 页面事件绑定
    bind: function () {
      // 重点批次进度表格
      $("#tbGrid").datagrid({
        columns: [[
          { field: 'ck', title: '选择', checkbox: true },
          { field: 'apsplandetailpreid', title: 'apsplandetailpreid', width: 100, hidden: true },
          { field: 'id', title: 'id', width: 100, hidden: true },
          { field: 'type', title: 'type', width: 60, hidden: true },
          { field: 'status', title: '点检状态', width: 60, hidden: true },
          { field: 'workflowstepid', title: '工序id', width: 100, hidden: true },
          { field: 'containerid', title: '批次id', width: 100, hidden: true },
          { field: 'factoryname', title: '分厂', width: 80 },
          { field: 'mfgordername', title: '订单号', width: 100 },
          { field: 'productname', title: '零件号', width: 100 },
          { field: 'containername', title: '批次号', width: 160 },
          { field: 'workflowstepname', title: '工序', width: 100 },
          { field: 'familylistnames', title: '型别', width: 60 },
          { field: 'containertype', title: '批次类型', width: 80 },
          { field: 'workflowinfo', title: '工艺规程', width: 100 },
          { field: 'qty', title: '在制数', width: 60 },
          {
            field: 'allset', title: '是否齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'materialset', title: '物料齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'toolset', title: '工装齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'auxset', title: '辅材齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'ncprogramset', title: '数控程序齐套', width: 80,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'checkpointset', title: '特殊过程齐套', width: 80,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'shipstepset', title: '实物齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'qualityset', title: '质量齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'resourceset', title: '设备齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          {
            field: 'workflowset', title: '工艺齐套', width: 60,
            formatter: function (value) {
              return value === '1' ? '已齐套' : (value === '0'?'预齐套':'不齐套');
            },
            styler: function (value, row, index) {
              if (value === '1') {
                return 'background-color:green;color:#fff;';
              } else {
                return 'background-color:red;color:#fff;';
              }
            }
          },
          { field: 'lastchangeemp', title: '修改人', width: 60 },
          {
            field: 'lastchangedate', title: '修改时间', width: 160,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          {
            field: 'marktype', title: '标记方式', width: 60,
            formatter: function (value) {
              return value === '1' ? '自动' : '手动';
            }
          },
          {
            field: 'estallsetdate', title: '预齐套时间', width: 160,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          {
            field: 'starttime', title: '计划开始时间', width: 160,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          },
          {
            field: 'endtime', title: '计划完成时间', width: 160,
            formatter: function (value) {
              if (value) {
                return value.replace('T', ' ');
              } else {
                return "";
              }
            }
          }
        ]],
        onLoadSuccess: function (data) {
          $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
            total: page.pagetotal,
            pageSize: page.pageSize,
            pageNumber: page.pageNumber
          });
          customizedEasyuiPagination('pp'); //定制化分页
        },
        onCheck: function (rowIndex, rowData) {
          if (rowData.status !== '已点检') { return }
          $('#ddlMaterialSet2').combobox('setValue', rowData.materialset);
          $('#ddlToolSet2').combobox('setValue', rowData.toolset);
          $('#ddlAuxSet2').combobox('setValue', rowData.auxset);
          $('#ddlWorkflowSet2').combobox('setValue', rowData.workflowset);
          $('#ddlNcProgramSet2').combobox('setValue', rowData.ncprogramset);
          $('#ddlCheckPointSet2').combobox('setValue', rowData.checkpointset);
          $('#ddlResourceSet2').combobox('setValue', rowData.resourceset);
          $('#ddlShipStepSet2').combobox('setValue', rowData.shipstepset);
          $('#ddlQualitySet2').combobox('setValue', rowData.qualityset);
          var selectData = $("#tbGrid").datagrid('getChecked');
          if (selectData.length >= 2) {
            $('#txtEstAllSetDate').textbox('clear');
          } else {
            if (rowData.estallsetdate) {
              var estallsetdate = rowData.estallsetdate.replace('T', ' ');
              $('#txtEstAllSetDate').textbox('setValue', estallsetdate);
            }
          }
        },
        onSelectAll: function (rows) {
          if (rows.length > 0) {
            $('#ddlMaterialSet2').combobox('setValue', rows[0].materialset);
            $('#ddlToolSet2').combobox('setValue', rows[0].toolset);
            $('#ddlAuxSet2').combobox('setValue', rows[0].auxset);
            $('#ddlWorkflowSet2').combobox('setValue', rows[0].workflowset);
            $('#ddlNcProgramSet2').combobox('setValue', rows[0].ncprogramset);
            $('#ddlCheckPointSet2').combobox('setValue', rows[0].checkpointset);
            $('#ddlResourceSet2').combobox('setValue', rows[0].resourceset);
            $('#ddlShipStepSet2').combobox('setValue', rows[0].shipstepset);
            $('#ddlQualitySet2').combobox('setValue', rows[0].qualityset);
            if (rows.length > 1) {
              // 多选时，清空预齐套时间
              $('#txtEstAllSetDate').textbox('clear');
            } else {
              if (rows[0].estallsetdate) {
                var estallsetdate = rows[0].estallsetdate.replace('T', ' ');
                $('#txtEstAllSetDate').textbox('setValue', estallsetdate);
              }
            }
          }
        },
        // 行点击
        onClickRow: function (index, row) {
          page.row = row;
          page.getDetails(row);
        }
      });

      // 物料齐套明细表格
       $("#tbMaterials").datagrid({
         columns: [[
           { field: 'productname', title: '件号', width: 120 },
           { field: 'description', title: '件号名称', width: 120 },
           { field: 'qtyrequired', title: '需求数量', width: 120 },
           { field: 'qty', title: '库存数量', width: 80 },
           { field: 'iscomp', title: '物料齐套' }
//           {
//             field: 'receivedate', title: '订单创建时间', width: 200,
//             formatter: function (value) {
//               if (value) {
//                 return value.replace('T', ' ');
//               } else {
//                 return "";
//               }
//             }
//           },
//           { field: 'sendstart', title: '是否下发' },
//           {
//             field: 'sendstartdate', title: '下发时间', width: 200,
//             formatter: function (value) {
//               if (value) {
//                 return value.replace('T', ' ');
//               } else {
//                 return "";
//               }
//             }
//           },
//           { field: 'sendstartemp', title: '下发人' }
         ]]
       });

      // 实物明细表格
      // $("#tbShip").datagrid({
      //   columns: [[
      //     { field: 'containername', title: '批次号', width: 200 },
      //     { field: 'workflowstepname', title: '工序名称', width: 200 },
      //     {
      //       field: 'endtime', title: '计划完成时间', width: 200,
      //       formatter: function (value) {
      //         if (value) {
      //           return value.replace('T', ' ');
      //         } else {
      //           return "";
      //         }
      //       }
      //     },
      //     {
      //       field: 'recivedate', title: '转入时间', width: 100,
      //       formatter: function (value) {
      //         if (value) {
      //           return value.replace('T', ' ');
      //         } else {
      //           return "";
      //         }
      //       }
      //     },
      //     { field: 'iscomp', title: '是否齐套', width: 100 }
      //   ]]
      // });

      // 工装明细表格
      $("#tbTools").datagrid({
        columns: [[
          { field: 'workflowstepname', title: '工序', width: 200 },
          { field: 'resourcetypename', title: '工装类型', width: 100 },
          // { field: 'tooltype', title: '工装类型', width: 100 },
          { field: 'toolname', title: '工装编码', width: 200 },
          { field: 'description', title: '工装名称', width: 200 },
          { field: 'qty', title: '需求数', width: 100 },
          { field: 'labstall', title: '库存数', width: 100 },
          { field: 'lackqty', title: '缺件数', width: 100 },
          { field: 'iscomp', title: '是否齐套', width: 100 }
        ]]
      });

      // 辅材明细表格
      $("#tbAuxs").datagrid({
        columns: [[
          { field: 'workflowstepname', title: '工序', width: 200 },
          { field: 'auxmaterialname', title: '辅材编号', width: 200 },
          { field: 'description', title: '辅材名称', width: 200 },
          { field: 'qty', title: '需求数', width: 100 },
          { field: 'labstall', title: '库存数', width: 100 },
          { field: 'lackqty', title: '缺件数', width: 100 },
          { field: 'iscomp', title: '是否齐套', width: 100 }
        ]]
      });

      // 特殊过程明细表格
      $("#tbCheckPoint").datagrid({
        columns: [[
          { field: 'specno', title: '工序号', width: 100 },
          { field: 'workflowstepname', title: '工序名称', width: 200 },
          {
            field: 'starttime', title: '开始时间', width: 200,
            formatter: function (value) {
              return page.row.starttime.replace('T', ' ');
            }
          },
          {
            field: 'endtime', title: '结束时间', width: 200,
            formatter: function (value) {
              return page.row.endtime.replace('T', ' ');
            }
          },
          { field: 'specialcoursespecreportno', title: '确认编号', width: 200 },
          { field: 'indate', title: '有效期', width: 200 },
          { field: 'iscomp', title: '是否齐套', width: 100 }
        ]]
      });

      // 数控程序明细表格
      $("#tbNcProgram").datagrid({
        columns: [[
          { field: 'specno', title: '工序号', width: 100 },
          { field: 'workflowstepname', title: '工序名称', width: 200 },
          {
            field: 'starttime', title: '开始时间', width: 200,
            formatter: function (value) {
              return page.row.starttime.replace('T', ' ');
            }
          },
          {
            field: 'endtime', title: '结束时间', width: 200,
            formatter: function (value) {
              return page.row.endtime.replace('T', ' ');
            }
          },
          { field: 'isnc', title: '是否数控程序', width: 200 },
          { field: 'nccode', title: '数控程序名称', width: 200 },
          { field: 'iscomp', title: '是否齐套', width: 100 }
        ]]
      });

      //设备明细
       $("#tbResource").datagrid({
        columns: [[
             { field: 'resourcename', title: '设备编码', width: 200 },
             { field: 'description', title: '设备名称', width: 200 },
             { field: 'erpstatus', title: '设备状态', width: 200 },
             { field: 'iscomp', title: '是否齐套', width: 200 },
        ]]
        });

      // 选项卡
      $('#tabs').tabs({
        border: false,
        onSelect: function (title) {
          if (page.DBDataSet) {
            $('#tbMaterials').datagrid('loadData', page.DBDataSet.dtMfg);
            // $('#tbShip').datagrid('loadData', page.DBDataSet.dtShipStep);
            $('#tbTools').datagrid('loadData', page.DBDataSet.dtTools);
            $('#tbAuxs').datagrid('loadData', page.DBDataSet.dtAux);
            $('#tbCheckPoint').datagrid('loadData', page.DBDataSet.dtCheckPoint);
            $('#tbNcProgram').datagrid('loadData', page.DBDataSet.dtNcProgram);
            $('#tbResource').datagrid('loadData', page.DBDataSet.dtResource);
          }
        }
      });

      var arrDdl = ['ddlAllSet', 'ddlMaterialSet', 'ddlToolSet', 'ddlAuxSet',
        'ddlWorkflowSet', 'ddlNcProgramSet', 'ddlCheckPointSet', 'ddlResourceSet',
        'ddlShipStepSet', 'ddlQualitySet',

        'ddlMaterialSet2', 'ddlToolSet2', 'ddlAuxSet2',
        'ddlWorkflowSet2', 'ddlNcProgramSet2', 'ddlCheckPointSet2', 'ddlResourceSet2',
        'ddlShipStepSet2', 'ddlQualitySet2'
      ];

      var columns = ['estallsetdate', 'allset', 'materialset', 'toolset',
        'auxset', 'workflowset', 'ncprogramset', 'checkpointset',
        'resourceset', 'shipstepset', 'qualityset', 'lastchangeemp',
        'lastchangedate', 'marktype'];

      // 为页面所有下拉框绑定并赋值
      arrDdl.forEach(function (item) {
        $('#' + item).combobox({
          data: [
            { label: '请选择', value: '' },
            { label: '预齐套', value: '0' },
            { label: '已齐套', value: '1' },
            { label: '不齐套', value: '2' }
          ],
          valueField: 'value',
          textField: 'label'
        });
      })

      // 点检状态
      $('#ddlCheck').combobox({
        data: [
          { label: '未点检', value: '未点检' },
          { label: '已点检', value: '已点检' }
        ],
        valueField: 'value',
        textField: 'label',
        onSelect: function (record) {
          page.clearTabsData();//清空tab页数据
          if (record.value === '未点检') {
            arrDdl.forEach(function (item) {
              $('#' + item).parent().hide();
            })
            // 隐藏齐套相关列
            columns.forEach(function (item) {
              $('#tbGrid').datagrid('hideColumn', item);
            })
            $("#tbGrid").datagrid('loadData', { total: 0, rows: [] });
            $('#btnCompute,#btnKeyCompute').show();//点检确认
            $('#btnAllSet').hide();//一键齐套
            $('#btnUpdate').hide();//修改齐套
            $('#btnReCompute').hide();//再次点检
            $('#btnUpdateQuality').hide();//修改工艺、设备、质量齐套
            $('#txtEstAllSetDate').parent().hide();//隐藏预齐套时间
          }

          if (record.value === '已点检') {
            arrDdl.forEach(function (item) {
              $('#' + item).parent().show();
            })
            // 显示齐套相关列
            columns.forEach(function (item) {
              $('#tbGrid').datagrid('showColumn', item);
            })
            $("#tbGrid").datagrid('loadData', { total: 0, rows: [] });
            $('#btnCompute,#btnKeyCompute').hide();//点检确认
            $('#btnAllSet').show();//一键齐套
            $('#btnUpdate').show();//修改齐套
            $('#btnReCompute').show();//再次点检
            $('#btnUpdateQuality').show();//修改工艺、设备、质量齐套
            $('#txtEstAllSetDate').parent().show();//显示预齐套时间
          }
        }
      });

      //分页事件
      $('#pp').pagination({
        onSelectPage: function (pageNumber, pageSize) {
          customizedEasyuiPagination('pp'); //定制化分页
          page.pageSize = pageSize;
          page.pageNumber = pageNumber;
          page.search();
        }
      });

      // 查询按钮
      $("#btnSearch").on("click", function () {
        page.pageNumber = 1;
        page.search();
      });

      // 重置
      $("#btnReset").on('click', function () {
        page.resetData();
      });

      // 点检确认
      $("#btnCompute").on('click', function () {
        page.spotcheck('insert');
      });
      // 一键点检
      $("#btnKeyCompute").on('click', function () {
        page.keyspotcheck('insert');
      });
      
      // 再次点检
      $("#btnReCompute").on('click', function () {
        page.spotcheck('update');
      });

      // 一键齐套
      $("#btnAllSet").on('click', function () {
        page.setAllSet();
      });

      // 修改齐套
      $("#btnUpdate").on('click', function () {
        page.update('update');
      });

      // 修改工艺、设备、质量齐套
      $("#btnUpdateQuality").on('click', function () {
        page.update('updateworkflow');
      });

      // 导出
      $("#btnExport").on('click', function () {
        page.exportExcel();
      });

    },
    // 初始化页面
    initData: function () {
      page.getFactory();
      $('#ddlCheck').combobox('setValue', '未点检');
    },
    // 查询
    search: function () {
      var formData = {
        action: "getData",
        pageSize: page.pageSize,
        pageNumber: page.pageNumber,
        factoryid: $('#ddlFactory').textbox('getValue'),//分厂
        mfgordername: $('#txtMfgordername').textbox('getValue'),//订单号
        productname: $('#txtProductname').textbox('getValue'),//件号
        containername: $('#txtContainername').textbox('getValue'),//批次号
        workflowstepname: $('#txtWorkflowstepname').textbox('getValue'),//工序
        allset: $('#ddlAllSet').combobox('getValue'),//是否齐套
        materialset: $('#ddlMaterialSet').combobox('getValue'),//物料齐套
        toolset: $('#ddlToolSet').combobox('getValue'),//工装工具齐套
        auxset: $('#ddlAuxSet').combobox('getValue'),//辅材齐套
        workflowset: $('#ddlWorkflowSet').combobox('getValue'),//工艺齐套
        ncprogramset: $('#ddlNcProgramSet').combobox('getValue'),//nc程序齐套
        checkpointset: $('#ddlCheckPointSet').combobox('getValue'),//特殊过程齐套
        resourceset: $('#ddlResourceSet').combobox('getValue'),//设备齐套
        shipstepset: $('#ddlShipStepSet').combobox('getValue'),//实物齐套
        qualityset: $('#ddlQualitySet').combobox('getValue'),//质量齐套
        ddlCheck: $('#ddlCheck').combobox('getValue'),//点击状态
        planStartDate:$('#planStartDate').datebox('getValue'),//计划开始时间
        planEndDate:$('#planEndDate').datebox('getValue')//计划结束时间
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getData",
        data: formData,
        cashe: false,
        async: true,
        dataType: 'json',
        beforeSend: function () {
          // 显示遮罩层
          $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
        },
        success: function (res) {
          // 隐藏遮罩层
          $.messager.progress('close');
          if (res.Result) {
            //给分页对象赋值
            page.pagetotal = res.RowCount;
            $('#tbGrid').datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
          } else {
            displayMessage(res.Message, false);
          }
        }
      });
    },
    // 查询明细
    getDetails: function (row) {
      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=getDetails",
        data: {
          action: "getDetails",
          mfgordername: row.mfgordername,
          containerid: row.containerid,
          workflowstepid: row.workflowstepid
        },
        cashe: false,
        async: true,
        dataType: 'json',
        beforeSend: function () {
          // 显示遮罩层
          $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
        },
        success: function (res) {
          // 隐藏遮罩层
          $.messager.progress('close');
          if (res.Result) {
            $('#tabs').tabs('select', '物料明细');
            page.DBDataSet = res.DBDataSet;//缓存数据，tabs页切换时从缓存中取值并重新渲染数据
            $('#tbMaterials').datagrid('loadData', res.DBDataSet.dtMfg);
            // $('#tbShip').datagrid('loadData', res.DBDataSet.dtShipStep);
            $('#tbTools').datagrid('loadData', res.DBDataSet.dtTools);
            $('#tbAuxs').datagrid('loadData', res.DBDataSet.dtAux);
            $('#tbCheckPoint').datagrid('loadData', res.DBDataSet.dtCheckPoint);
            $('#tbNcProgram').datagrid('loadData', res.DBDataSet.dtNcProgram);
            $('#tbResource').datagrid('loadData', page.DBDataSet.dtResource);
          } else {
            displayMessage(res.Message, false);
          }
        }
      });
    },
    // 点检确认
    spotcheck: function (ddltype) {
      var map = [{ type: 'insert', text: '点检确认' }, { type: 'update', text: '再次点检' }];
      var type = ddltype || 'insert';
      var text = map.filter(function (item) { return item.type === type })[0].text;

      var selectData = $("#tbGrid").datagrid('getChecked');
      if (selectData.length === 0) {
        return displayMessage('请勾选需要【' + text + '】的记录！', false);
      }

      $.messager.confirm('确认', '你确认要' + text + '吗?', function (r) {
        if (!r) { return; }
        $.ajax({
          type: "post",
          url: page.mainUrl + "?actions=spotcheck",
          data: {
            action: "spotcheck",
            ddlType: type,
            postData: JSON.stringify(selectData),
          },
          cashe: false,
          dataType: 'json',
          beforeSend: function () {
            // 显示遮罩层
            $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
          },
          success: function (res) {
            // 隐藏遮罩层
            $.messager.progress('close');
            if (res.Result) {
              displayMessage(text + '成功', true);
              $('#tbGrid').datagrid('loadData', []);
            } else {
              displayMessage(res.Message, false);
            }
          }
        })
      });
    },
    //一键点检
    keyspotcheck:function(ddltype){
    var formData = {
        action: "keyspotcheck",
        ddlType: ddltype,
        factoryid: $('#ddlFactory').textbox('getValue'),//分厂
        mfgordername: $('#txtMfgordername').textbox('getValue'),//订单号
        productname: $('#txtProductname').textbox('getValue'),//件号
        containername: $('#txtContainername').textbox('getValue'),//批次号
        workflowstepname: $('#txtWorkflowstepname').textbox('getValue'),//工序
        ddlCheck: $('#ddlCheck').combobox('getValue'),//点检状态
        planStartDate:$('#planStartDate').datebox('getValue'),//计划开始时间
        planEndDate:$('#planEndDate').datebox('getValue')//计划结束时间
      };
        $.messager.confirm('确认', '你确认要一键点检吗?', function (r) {
        if (!r) { return; }
        $.ajax({
          type: "post",
          url: page.mainUrl + "?actions=keyspotcheck",
          data: formData,
          cashe: false,
          dataType: 'json',
          beforeSend: function () {
            // 显示遮罩层
            $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
          },
          success: function (res) {
            // 隐藏遮罩层
            $.messager.progress('close');
            if (res.Result) {
              displayMessage(res.Message, true);
              $('#tbGrid').datagrid('loadData', []);
            } else {
              displayMessage(res.Message, false);
            }
          }
        })
      });
    },
    // 一键齐套
    setAllSet: function () {
      var selectData = $("#tbGrid").datagrid('getChecked');
      if (selectData.length === 0) {
        return displayMessage('请勾选需要【一键齐套】的记录！', false);
      }

      $.messager.confirm('确认', '你确认要一键齐套吗?', function (r) {
        if (!r) { return; }
        $.ajax({
          type: "post",
          url: page.mainUrl + "?actions=setAllSet",
          data: {
            action: "setAllSet",
            postData: JSON.stringify(selectData),
          },
          cashe: false,
          beforeSend: function () {
            // 显示遮罩层
            $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
          },
          dataType: 'json',
          success: function (res) {
            // 隐藏遮罩层
            $.messager.progress('close');
            if (res.Result) {
              displayMessage('一键齐套成功', true);
              $('#tbGrid').datagrid('loadData', []);
            } else {
              displayMessage(res.Message, false);
            }
          }
        })
      });
    },
    // 更新
    update: function (updatetype) {
      var map = [
        {
          type: 'update',
          text: '修改齐套',
          note: '备注：此操作不会修改【工艺】、【设备】、【质量】的齐套性。'
        },
        {
          type: 'updateworkflow',
          text: '修改工艺、设备、质量齐套',
          note: '备注：此操作不会修改【物料】、【工装】、【辅材】、【数控程序】、【特殊过程】、【实物】的齐套性。'
        }
      ];
      var type = updatetype || 'update';
      var text = map.filter(function (item) { return item.type === type })[0].text;
      var note = map.filter(function (item) { return item.type === type })[0].note;

      var selectData = $("#tbGrid").datagrid('getChecked');
      if (selectData.length === 0) {
        return displayMessage('请勾选需要【' + text + '】的记录！', false);
      }

      $.messager.confirm('确认', '你确认要' + text + '吗？' + note, function (r) {
        if (!r) { return; }
        $.ajax({
          type: "post",
          url: page.mainUrl + "?actions=update",
          data: {
            action: "update",
            type: type,
            materialset: $('#ddlMaterialSet2').combobox('getValue'),//物料齐套
            toolset: $('#ddlToolSet2').combobox('getValue'),//工装工具齐套
            auxset: $('#ddlAuxSet2').combobox('getValue'),//辅材齐套
            workflowset: $('#ddlWorkflowSet2').combobox('getValue'),//工艺齐套
            ncprogramset: $('#ddlNcProgramSet2').combobox('getValue'),//nc程序齐套
            checkpointset: $('#ddlCheckPointSet2').combobox('getValue'),//特殊过程齐套
            resourceset: $('#ddlResourceSet2').combobox('getValue'),//设备齐套
            shipstepset: $('#ddlShipStepSet2').combobox('getValue'),//实物齐套
            qualityset: $('#ddlQualitySet2').combobox('getValue'),//质量齐套
            estallsetdate: $('#txtEstAllSetDate').textbox('getValue'),//预齐套时间
            postData: JSON.stringify(selectData),
          },
          beforeSend: function () {
            // 显示遮罩层
            $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
          },
          cashe: false,
          dataType: 'json',
          success: function (res) {
            // 隐藏遮罩层
            $.messager.progress('close');
            if (res.Result) {
              displayMessage(text + '齐套成功', true);
              $('#tbGrid').datagrid('loadData', []);
            } else {
              displayMessage(res.Message, false);
            }
          }
        })
      });
    },
    // 获取分厂列表
    getFactory: function () {
      $.ajax({
        type: "post",
        url: getRootPath() + "/Ashx/ApsHandler/EmployeeMaintPage.ashx?actions=getFactory",
        data: { action: "GetFactory" },
        cashe: false,
        dataType: 'json',
        success: function (res) {
          if (res.Result) {
            // 绑定弹出框分厂下拉框
            $("#ddlFactory").combobox({
              valueField: 'factoryid',
              textField: 'factoryname',
              panelHeight: 200,
              data: res.DBTable
            });

            $.ajax({
              type: "post",
              url: page.mainUrl + "?actions=getUserInfo",
              data: { action: "getUserInfo" },
              cashe: false,
              dataType: 'json',
              success: function (res) {
                if (res.Result) {
                  if (res.ReturnData.FactoryID) {
                    $("#ddlFactory").combobox('select', res.ReturnData.FactoryID);
                    $('#ddlFactory').combobox('disable');
                  }
                } else {
                  displayMessage(res.Message, false);
                }
              }
            });
          }
        }
      });
    },
    // 清空tab页数据
    clearTabsData: function () {
      page.DBDataSet = null;
      $('#tbMaterials').datagrid('loadData', []);
      // $('#tbShip').datagrid('loadData', []);
      $('#tbTools').datagrid('loadData', []);
      $('#tbAuxs').datagrid('loadData', []);
      $('#tbCheckPoint').datagrid('loadData', []);
      $('#tbNcProgram').datagrid('loadData', []);
    },
    // 重置
    resetData: function () {
      $("#tbGrid").datagrid('loadData', { total: 0, rows: [] });
      page.pageNumber = 1;
      page.pageSize = 10;

      $('#pp').pagination('refresh', { // 改变选项并刷新分页栏信息
        total: 0,
        pageNumber: 1,
        pageSize: 10
      });

      $("#txtMfgordername").textbox('clear');
      $("#txtProductname").textbox('clear');
      $("#txtContainername").textbox('clear');
      $('#txtWorkflowstepname').textbox('clear');

      $("#ddlAllSet").combobox('select', '');
      $("#ddlMaterialSet").combobox('select', '');
      $("#ddlToolSet").combobox('select', '');
      $("#ddlAuxSet").combobox('select', '');
      $("#ddlWorkflowSet").combobox('select', '');
      $("#ddlNcProgramSet").combobox('select', '');
      $("#ddlCheckPointSet").combobox('select', '');
      $("#ddlResourceSet").combobox('select', '');
      $("#ddlShipStepSet").combobox('select', '');
      $("#ddlQualitySet").combobox('select', '');

      $("#ddlAllSet2").combobox('select', '');
      $("#ddlMaterialSet2").combobox('select', '');
      $("#ddlToolSet2").combobox('select', '');
      $("#ddlAuxSet2").combobox('select', '');
      $("#ddlWorkflowSet2").combobox('select', '');
      $("#ddlNcProgramSet2").combobox('select', '');
      $("#ddlCheckPointSet2").combobox('select', '');
      $("#ddlResourceSet2").combobox('select', '');
      $("#ddlShipStepSet2").combobox('select', '');
      $("#ddlQualitySet2").combobox('select', '');
      $("#txtEstAllSetDate").textbox('clear');
      $('#planStartDate').datebox('clear'),//计划开始时间
      $('#planEndDate').datebox('clear')//计划结束时间
      page.clearTabsData();//清空tab页数据
    },
    // 导出
    exportExcel: function () {
      var formData = {
        action: "exportExcel",
        factoryid: $('#ddlFactory').textbox('getValue'),//分厂
        mfgordername: $('#txtMfgordername').textbox('getValue'),//订单号
        productname: $('#txtProductname').textbox('getValue'),//件号
        containername: $('#txtContainername').textbox('getValue'),//批次号
        workflowstepname: $('#txtWorkflowstepname').textbox('getValue'),//工序
        allset: $('#ddlAllSet').combobox('getValue'),//是否齐套
        materialset: $('#ddlMaterialSet').combobox('getValue'),//物料齐套
        toolset: $('#ddlToolSet').combobox('getValue'),//工装工具齐套
        auxset: $('#ddlAuxSet').combobox('getValue'),//辅材齐套
        workflowset: $('#ddlWorkflowSet').combobox('getValue'),//工艺齐套
        ncprogramset: $('#ddlNcProgramSet').combobox('getValue'),//nc程序齐套
        checkpointset: $('#ddlCheckPointSet').combobox('getValue'),//特殊过程齐套
        resourceset: $('#ddlResourceSet').combobox('getValue'),//设备齐套
        shipstepset: $('#ddlShipStepSet').combobox('getValue'),//实物齐套
        qualityset: $('#ddlQualitySet').combobox('getValue'),//质量齐套
        ddlCheck: $('#ddlCheck').combobox('getValue')//点击状态
      };

      $.ajax({
        type: "Post",
        url: page.mainUrl + "?actions=exportExcel",
        data: formData,
        cashe: false,
        async: true,
        beforeSend: function () {
          // 显示遮罩层
          $.messager.progress({ title: '提示', msg: '程序处理中，请稍后...', text: '' });
        },
        success: function (data) {
          // 隐藏遮罩层
          $.messager.progress('close');

          var result = JSON.parse(data);
          if (result.Result) {
            //通过创建a标签实现
            var link = document.createElement("a");
            link.href = result.ReturnData.url;
            //对下载的文件命名
            link.download = result.ReturnData.filename;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
          } else {
            displayMessage(result.Message, false);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          $('#tbGrid').datagrid('loaded');
          $(this).removeAttr("disabled"); //恢复按钮
          alert(XMLHttpRequest.responseText);
        }
      });
    }
  };

  $(function () {
    page.init();
  });
</script>